package com.open.system.controller;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.open.system.domain.LoanAdminLogDO;
import com.open.system.service.LoanAdminLogService;
import com.open.system.service.LoanShopService;
import com.open.common.controller.BaseController;
import com.open.common.utils.PageUtils;
import com.open.common.utils.Query;
import com.open.common.utils.R;

/**
 * 后台日志
 */
 
@Controller
@RequestMapping("/system/loanAdminLog")
public class LoanAdminLogController extends BaseController {
	@Autowired
	private LoanAdminLogService loanAdminLogService;
	
	@GetMapping()
	String LoanAdminLog(){
	    return "system/loanAdminLog/loanAdminLog";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		String shopId=getUser().getEmail();//店铺ID
		if(shopId!=null && shopId!="" && !"1".equals(shopId)){
			params.put("remark4",shopId);
		}
		//查询列表数据
		params.put("status","2");
        Query query = new Query(params);
		List<LoanAdminLogDO> loanAdminLogList = loanAdminLogService.list(query);
		int total = loanAdminLogService.count(query);
		PageUtils pageUtils = new PageUtils(loanAdminLogList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	String add(){
	    return "system/loanAdminLog/add";
	}

	@GetMapping("/edit/{id}")
	String edit(@PathVariable("id") Long id,Model model){
		LoanAdminLogDO loanAdminLog = loanAdminLogService.get(id);
		model.addAttribute("loanAdminLog", loanAdminLog);
	    return "system/loanAdminLog/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( LoanAdminLogDO loanAdminLog){
		if(loanAdminLogService.save(loanAdminLog)>0){
			return R.ok();
		}
		return R.error();
	}
	
	
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( LoanAdminLogDO loanAdminLog){
		loanAdminLogService.update(loanAdminLog);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Long id){
		if(loanAdminLogService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Long[] ids){
		loanAdminLogService.batchRemove(ids);
		return R.ok();
	}
	
}
